package com.example.teachingSystem.controller;

import com.baomidou.mybatisplus.annotation.TableName;
import com.example.teachingSystem.pojo.form.score.AddScoreForm;
import com.example.teachingSystem.pojo.form.score.ScorePageQuery;
import com.example.teachingSystem.pojo.form.score.UpdateScoreForm;
import com.example.teachingSystem.pojo.vo.ScoreInfoVo;
import com.example.teachingSystem.service.ScoreService;
import com.example.teachingSystem.utils.result.PageResult;
import com.example.teachingSystem.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/scores")
@Tag(name = "成绩管理模块")
public class ScoreController {
    @Autowired
    private ScoreService scoreService;

    @PostMapping("/addScore")
    @Operation(summary = "添加成绩（管理员,老师）", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> addScore(@RequestBody AddScoreForm addScoreForm) {
        return scoreService.addScore(addScoreForm);
    }

    @PutMapping("/updateScore")
    @Operation(summary = "更新成绩（管理员、老师）", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> updateScore(@RequestBody UpdateScoreForm updateScoreForm) {
        return scoreService.updateScore(updateScoreForm);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除成绩（管理员、老师）", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> deleteScoreByScoreId(@RequestParam Long scoreId) {
        return scoreService.deleteScoreByScoreId(scoreId);
    }

    @GetMapping("/getByAdmin")
    @Operation(summary = "管理员获取所有用户的成绩", security = {@SecurityRequirement(name = "Authorization")})
    public PageResult<ScoreInfoVo> showScoresByAdmin(ScorePageQuery scorePageQuery) {
        return scoreService.showScoresByAdmin(scorePageQuery);
    }


    @GetMapping("/getByTeacher")
    @Operation(summary = "老师获取自己学生的成绩", security = {@SecurityRequirement(name = "Authorization")})
    public PageResult<ScoreInfoVo> showScoresByTeacher(ScorePageQuery scorePageQuery) {
        return scoreService.showScoresByTeacher(scorePageQuery);
    }

    @GetMapping("/getByStudent")
    @Operation(summary = "学生获取自己的成绩", security = {@SecurityRequirement(name = "Authorization")})
    public PageResult<ScoreInfoVo> showScoresByStudent(ScorePageQuery scorePageQuery) {
        return scoreService.showScoresByStudent(scorePageQuery);
    }
}
